package com.geostar.constructionland.common.dao.impl;

import com.geostar.constructionland.common.dao.LogMongoSptDao;
import com.geostar.constructionland.common.entity.logs.mongolog.LogMongoSpt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author yelll
 * @since 2020-6-19 15:51
 **/
@Component
public class LogMongoSptDaoImpl implements LogMongoSptDao {
    @Autowired
    MongoTemplate mongoTemplate;

    @Override
    public void saveBatch(List<LogMongoSpt> logMongoSpts) {
        mongoTemplate.insert(logMongoSpts);
    }

    @Override
    public void saveLogMongoSpt(LogMongoSpt logMongoSpt) {
        mongoTemplate.save(logMongoSpt);
    }

    @Override
    public LogMongoSpt getLogMongoSpt(String id) {
        Query query = new Query();
        query.addCriteria(Criteria.where("id").is(id));
        return mongoTemplate.findOne(query, LogMongoSpt.class);
    }

    @Override
    public List<LogMongoSpt> getLogSpts() {
        return mongoTemplate.findAll(LogMongoSpt.class);
    }
}
